
package com.RJAI.gemini.controller;


import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.json.JSONObject;


import java.io.IOException;

import javax.servlet.http.HttpServletResponse;

import com.RJAI.gemini.service.impl.ClaudeServiceImpl;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/*
作者信息
WeChat:ciansec
QQ:1068092013
 */
@RestController
public class ClaudeController {


    @Autowired
    private ClaudeServiceImpl claudeService;

    @PostMapping({"{key}/v1/messages"})
    public Object getGeminiAi(HttpServletResponse response, @PathVariable("key") String key, @RequestBody JSONObject jsonObject) throws InterruptedException, IOException {
        System.out.println( "jsonObject = " + jsonObject );
        //得到请求体中的模型
        String model = jsonObject.getStr( "model" );
        //判断是否流式
        Boolean stream = jsonObject.getBool( "stream" );
        if (ObjectUtil.isNotNull( stream ) && stream) {
            return claudeService.claudeMessageWithStream(response, key,jsonObject,model );
            //流式
        } else {
            return claudeService.claudeMessageWithNotStream( response,key, jsonObject, model );
            //非流式
        }


    }
}
